<html>
<head><meta charset="utf-8"><title>(no topic) · t-libs/stdarch · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/index.html">t-libs/stdarch</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html">(no topic)</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="178329237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178329237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178329237">(Oct 16 2019 at 21:21)</a>:</h4>
<p>this is my first try <a href="https://github.com/xiph/rav1e/pull/1768/commits/3cd84ecc2bb1dd905bb54f2dd69bb3506be70b17" target="_blank" title="https://github.com/xiph/rav1e/pull/1768/commits/3cd84ecc2bb1dd905bb54f2dd69bb3506be70b17">https://github.com/xiph/rav1e/pull/1768/commits/3cd84ecc2bb1dd905bb54f2dd69bb3506be70b17</a></p>



<a name="178360583"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178360583" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178360583">(Oct 17 2019 at 08:27)</a>:</h4>
<p>and apparently the main problem was me misreading what the assembly using it was expecting</p>



<a name="178361534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178361534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178361534">(Oct 17 2019 at 08:44)</a>:</h4>
<p>I mean, if you just want a static array that's aligned, you can do:</p>
<div class="codehilite"><pre><span></span><span class="cp">#[repr(align(N)]</span><span class="w"> </span><span class="k">struct</span> <span class="nc">MyArray</span><span class="p">([</span><span class="n">T</span><span class="p">;</span><span class="w"> </span><span class="n">M</span><span class="p">]);</span><span class="w"></span>
<span class="k">static</span><span class="w"> </span><span class="n">FOO</span>: <span class="nc">MyArray</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">MyArray</span><span class="p">([</span><span class="w"> </span><span class="p">...</span><span class="w"> </span><span class="p">]);</span><span class="w"></span>
</pre></div>



<a name="178361635"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178361635" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178361635">(Oct 17 2019 at 08:46)</a>:</h4>
<p>You can set the <code>N</code> in <code>repr(align(N))</code> to whatever alignment you want, and the alignment of the array will be <code>max(N, align_of&lt;T&gt;)</code></p>



<a name="178451555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178451555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178451555">(Oct 18 2019 at 07:52)</a>:</h4>
<p>yes, I can simplify the notation</p>



<a name="178452402"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178452402" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178452402">(Oct 18 2019 at 08:05)</a>:</h4>
<p>So that's the best way we have for that</p>



<a name="178452500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178452500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178452500">(Oct 18 2019 at 08:07)</a>:</h4>
<p>In C++ things are a bit better because we can use const generics and metaprogramming to set the type alignment, but otherwise things are similar</p>



<a name="178452568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178452568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178452568">(Oct 18 2019 at 08:08)</a>:</h4>
<div class="codehilite"><pre><span></span><span class="k">template</span><span class="o">&lt;</span><span class="k">typename</span> <span class="n">T</span><span class="p">,</span> <span class="kt">size_t</span> <span class="n">N</span><span class="o">&gt;</span>
<span class="k">struct</span> <span class="n">simd_array</span> <span class="p">{</span>
    <span class="k">alignas</span><span class="p">(</span><span class="k">sizeof</span><span class="p">(</span><span class="n">T</span><span class="p">)</span> <span class="o">*</span> <span class="n">N</span><span class="p">)</span> <span class="n">T</span> <span class="n">data</span><span class="p">[</span><span class="n">N</span><span class="p">];</span>
<span class="p">};</span>
</pre></div>



<a name="178452584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178452584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178452584">(Oct 18 2019 at 08:08)</a>:</h4>
<p>quite a bit</p>



<a name="178452626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/208962-t-libs/stdarch/topic/%28no%20topic%29/near/178452626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Luca Barbato <a href="https://rust-lang.github.io/zulip_archive/stream/208962-t-libs/stdarch/topic/(no.20topic).html#178452626">(Oct 18 2019 at 08:09)</a>:</h4>
<p>newtyping is fine IMHO</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>